package com.tongji.housediy.view
{
	import com.tongji.housediy.events.commonEvent.BeginDrawFreeFloorEvent;
	import com.tongji.housediy.events.commonEvent.SetCompStateEvent;
	import com.tongji.housediy.events.commonEvent.ShowHideTitleWindowEvent;
	import com.tongji.housediy.model.FloorModel;
	import com.tongji.housediy.utils.DragDropManager;
	
	import flash.events.MouseEvent;
	
	import org.robotlegs.mvcs.Mediator;
	
	import spark.filters.GlowFilter;
	
	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class FloorAreaMediator extends Mediator
	{
		[Inject]
		public var view:FloorAreaComp;
		
		override public function onRegister():void
		{
			view.freeFormFloorBtn.addEventListener(MouseEvent.CLICK, freeFormFloorBtnClickHandler);
			view.squareFloorBtn.addEventListener(MouseEvent.MOUSE_DOWN, squareFloorBtnMouseDownHandler);
			
			this.addContextListener(SetCompStateEvent.RESET_FILTER, setCompFilterHandler, SetCompStateEvent);
		}
		
		private function freeFormFloorBtnClickHandler(event:MouseEvent):void
		{
			view.freeFormFloorBtn.filters = [new GlowFilter(0xB5E061, 1, 8, 8, 8)];
			
			dispatch(new ShowHideTitleWindowEvent(ShowHideTitleWindowEvent.HIDE_TITLE_WINDOW));
			dispatch(new BeginDrawFreeFloorEvent(BeginDrawFreeFloorEvent.DRAW_FREE_FLOOR));
		}
		
		private function squareFloorBtnMouseDownHandler(event:MouseEvent):void
		{
			DragDropManager.startDragRoomChild(view, event, "independentFloor");
		}
		
		private function setCompFilterHandler(event:SetCompStateEvent):void
		{
			view.freeFormFloorBtn.filters = null;
		}
	}
}